package com.segersten.kalaha.util.authentication;

import java.util.Map;


import com.google.appengine.repackaged.com.google.common.util.Base64;
import com.google.appengine.repackaged.com.google.common.util.Base64DecoderException;
import com.restfb.Facebook;

public class SignedRequest {
	
	@Facebook
	private String user_id;
	
	@Facebook
	private String oauth_token;
	
	public String getUserId() {
		return user_id;
	}
	
	public String getOauthToken() {
		return oauth_token;
	}

	public static void main(String [] args) {
		String msg = "eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjEyOTEyMzAwMDAsImlzc3VlZF9hdCI6MTI5MTIyMzkzNSwib2F1dGhfdG9rZW4iOiIxMjgxODE2MzcyNDMwNzh8Mi4zZ0lfRWh0UzJaeU9WSDFvbVY5eEhnX18uMzYwMC4xMjkxMjMwMDAwLTc1ODM3Nzc0Nnx1b04ySXNGMDlYNDMtY2VscndLUFd0aGVHRFUiLCJ1c2VyX2lkIjoiNzU4Mzc3NzQ2In0";
		try {
			String data = base64_url_decode(msg);
			System.out.println(data);
			
			msg = "eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImlzc3VlZF9hdCI6MTI5OTUzMDc3OSwidXNlciI6eyJjb3VudHJ5Ijoic2UiLCJsb2NhbGUiOiJzdl9TRSIsImFnZSI6eyJtaW4iOjIxfX19";
			data = base64_url_decode(msg);
			System.out.println(data);
			
			msg = "{\"algorithm\":\"HMAC-SHA256\",\"expires\":1299607200,\"issued_at\":1299600848,\"oauth_token\":\"169238706460070|2.lDeSflRekaO9VXpsoOOlVg__.3600.1299607200-758377746|uTTr4nIAP6X4QyR3Hq0aaHDig-A\",\"user\":{\"country\":\"se\",\"locale\":\"sv_SE\",\"age\":{\"min\":21}},\"user_id\":\"758377746\"}";
			//Map<String, String> par = JSonUtil.decode(data);
			//System.out.println(par);
			
			//System.out.println(par.get("user_id"));
		} catch (Base64DecoderException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	private static String base64_url_decode(String input) throws Base64DecoderException {
		return new String(Base64.decode(input));
	  }

}

/*class JSonUtil {

	public static Map<String, String> decode(String content)  {
		if (content==null) { return null; }
		try {
		Gson gson = new Gson();
		Type mapType = new TypeToken<Map<String,String>>() {}.getType();
		return gson.fromJson(content, mapType);
		} catch (JsonParseException e) {
			return null;
		}
	}
}*/

/*
 {"algorithm":"HMAC-SHA256","expires":1299607200,"issued_at":1299600848,"oauth_token":"169238706460070|2.lDeSflRekaO9VXpsoOOlVg__.3600.1299607200-758377746|uTTr4nIAP6X4QyR3Hq0aaHDig-A","user":{"country":"se","locale":"sv_SE","age":{"min":21}},"user_id":"758377746"} 
*/